<%-- Include --%>
<#include "../auxftl/constants.ftl">
<#include "../auxftl/outpututils.ftl">
<#include "../auxftl/inpututils.ftl">
<#assign propertyList = createPropertyList() />
<%@ include file="layout/includes.jsp" %>

<%-- Page layout --%>
<stripes:layout-render name="/layout/layout.jsp" title="${entityName}List">
  <stripes:layout-component name="contents">

    <%-- Load resource bundle --%>
    <fmt:setBundle basename="messages" var="msgs"/>

    <%-- Search form and result list --%>
    <stripes:form beanclass="${controllerPackage}.${entityName}List" focus="">

      <%-- Print errors --%>
      <stripes:errors/>

      <%-- Filter controls --%>
      <div id="pseudoLegend" ><fmt:message bundle="${'$'}{msgs}" key="custom.global.title.searchFilter"/><a id="pseudoLegendWrapper" class="wrapperArrowUp" href="javascript:toggleVisibility('wrapFieldset', 'pseudoLegendWrapper')"></a></div>
      <fieldset id='wrapFieldset'>
        <@renderSearchProperties />

        <%-- Filter submit buttons --%>
        <div class="buttons">
          <stripes:submit name="doFilter"><fmt:message bundle="${'$'}{msgs}" key="custom.global.button.search"/></stripes:submit>
          <stripes:reset name="doReset"><fmt:message bundle="${'$'}{msgs}" key="custom.global.button.reset"/></stripes:reset>
        </div>
      </fieldset>

      <br />

      <%-- If there is no action bean, from which will be resultset taken, create new --%>
      <c:if test="${'$'}{empty actionBean}">
        <stripes:useActionBean var="actionBean" beanclass="${controllerPackage}.${entityName}List"/>
      </c:if>

      <stripes:link href="/${entityName}Edit.jsp">
        <fmt:message bundle="${'$'}{msgs}" key="custom.global.button.create"/>
      </stripes:link>

      <%-- If result list is not empty, print it --%>
      <c:choose>
        <c:when test="${'$'}{! empty actionBean.resultList}">
          <table>
            <tr class="rowHead">
              <@renderResultHeaderCells controllerPackage=controllerPackage entityName=entityName/>
              <th></th>
            </tr>
            <c:forEach items="${'$'}{actionBean.resultList}" var="i" varStatus="rowstat">
              <tr class="${'$'}{rowstat.count mod 2 == 0 ? "rowOdd" : "rowEven"}">
                <@renderResultCells rowIteratorName="i"/>
                <td>
                  <stripes:link beanclass="${controllerPackage}.${entityName}Edit" event="doLoad">
                    <stripes:param name="${componentName}.${pojo.identifierProperty.name}" value="${'$'}{i.${pojo.identifierProperty.name}}"/>
                    <fmt:message bundle="${'$'}{msgs}" key="custom.global.button.edit"/>
                  </stripes:link>
                </td>
              </tr>
            </c:forEach>
          </table>
        </c:when>
        <c:otherwise>
          <fmt:message bundle="${'$'}{msgs}" key="custom.global.label.emptySearch"/>
        </c:otherwise>
      </c:choose>

      <%-- Paging --%>
      <c:if test="${'$'}{! empty actionBean.resultList}">
        <div class="pagination">
          <span class="paginationleft">
            <c:choose>
              <c:when test="${'$'}{actionBean.prevPageExists}">
                <stripes:link beanclass="${controllerPackage}.${entityName}List" event="doFilter">
                  <stripes:param name="firstResult" value="0"/>
                  <@renderLinkFilterParams componentName=componentName/>
                  <stripes:param name="orderBy" value="${'$'}{actionBean.orderBy}"/>
                  <stripes:param name="orderAct" value="${'$'}{actionBean.orderAsc}"/>
                  <fmt:message bundle="${'$'}{msgs}" key="custom.global.label.firstPage"/>
                </stripes:link>
              </c:when>
              <c:otherwise>
                <fmt:message bundle="${'$'}{msgs}" key="custom.global.label.firstPage"/>
              </c:otherwise>
            </c:choose>
            <c:out value="|" />
            <c:choose>
              <c:when test="${'$'}{actionBean.prevPageExists}">
                <stripes:link beanclass="${controllerPackage}.${entityName}List" event="doFilter">
                  <stripes:param name="firstResult" value="${'$'}{actionBean.prevFirstResult}"/>
                  <@renderLinkFilterParams componentName=componentName/>
                  <stripes:param name="orderBy" value="${'$'}{actionBean.orderBy}"/>
                  <stripes:param name="orderAct" value="${'$'}{actionBean.orderAsc}"/>
                  <fmt:message bundle="${'$'}{msgs}" key="custom.global.label.previousPage"/>
                </stripes:link>
              </c:when>
              <c:otherwise>
                <fmt:message bundle="${'$'}{msgs}" key="custom.global.label.previousPage"/>
              </c:otherwise>
            </c:choose>
          </span>
          <span class="paginationright">
            <c:choose>
              <c:when test="${'$'}{actionBean.nextPageExists}">
                <stripes:link beanclass="${controllerPackage}.${entityName}List" event="doFilter">
                  <stripes:param name="firstResult" value="${'$'}{actionBean.nextFirstResult}"/>
                  <@renderLinkFilterParams componentName=componentName/>
                  <stripes:param name="orderBy" value="${'$'}{actionBean.orderBy}"/>
                  <stripes:param name="orderAct" value="${'$'}{actionBean.orderAsc}"/>
                  <fmt:message bundle="${'$'}{msgs}" key="custom.global.label.nextPage"/>
                </stripes:link>
              </c:when>
              <c:otherwise>
                <fmt:message bundle="${'$'}{msgs}" key="custom.global.label.nextPage"/>
              </c:otherwise>
            </c:choose>
            <c:out value="|" />
            <c:choose>
              <c:when test="${'$'}{actionBean.nextPageExists}">
                <stripes:link beanclass="${controllerPackage}.${entityName}List" event="doFilter">
                  <stripes:param name="firstResult" value="${'$'}{actionBean.lastFirstResult}"/>
                  <@renderLinkFilterParams componentName=componentName/>
                  <stripes:param name="orderBy" value="${'$'}{actionBean.orderBy}"/>
                  <stripes:param name="orderAct" value="${'$'}{actionBean.orderAsc}"/>
                  <fmt:message bundle="${'$'}{msgs}" key="custom.global.label.lastPage"/>
                </stripes:link>
              </c:when>
              <c:otherwise>
                <fmt:message bundle="${'$'}{msgs}" key="custom.global.label.lastPage"/>
              </c:otherwise>
            </c:choose>
          </span>
        </div>
      </c:if>
    </stripes:form>
  </stripes:layout-component>
</stripes:layout-render>
